<?php

require_once 'PHPUnit/Framework.php';
require_once '../MagicObject.php';

// Test Priority

class A {
	public function moo() {
		echo 'moo !';
	}
}

class B {
	public function waf() {
		echo 'waf !';
	}
}

class BA {
	public function moo() {
		echo 'woof !';
	}
	public function waf() {
		echo 'waf !';
	}
}

class C {
	public function kwakwa() {
		echo 'kwa ! kwa !';
	}
}

class ABC extends MagicObject {
	public function __construct () {
		parent::__construct(array(new A, new B, new C));
	}
}

class CBA extends MagicObject {
	public function __construct () {
		parent::__construct(array(new C, new B, new A));
	}
}

class CBA_A extends MagicObject {
	public function __construct () {
		parent::__construct(array(new C, new BA, new A));
	}
}

// Test Getter

class DRo  extends MagicObject {
	public $name = 'D Object';
	public $universalResponse = 48;
	
	public function getAge () {
		return 28;
	}
	
	public function getUniversalResponse () {
		return 42;
	}
}

class MagicObjectTest extends PHPUnit_Framework_TestCase {
	public function testPriority () {
		$d = new ABC;
		
		ob_start();
		$d->moo();
		$d->waf();
		$d->kwakwa();
		
		$this->assertEquals('moo !waf !kwa ! kwa !', ob_end_clean());
		
		$d = new CBA;
		
		ob_start();
		$d->moo();
		$d->waf();
		$d->kwakwa();
		
		$this->assertEquals('moo !waf !kwa ! kwa !', ob_end_clean());
		
		$d = new CBA_A;
		
		ob_start();
		$d->moo();
		$d->waf();
		$d->kwakwa();
		
		$this->assertEquals('moo !maa !kwa ! kwa !', ob_end_clean());
	}
	
	public function testGetter () {
		$d = new DRo;
		
		$this->assertEquals($d->getName(), 'D Object', 'getName()');
		$this->assertEquals($d->getName, 'D Object', 'getName ruby style');
		$this->assertEquals($d->name, 'D Object', 'read name attribute');
		$this->assertEquals($d->getAge(), 28, 'getAge()');
		$this->assertEquals($d->getAge, 28, 'getAge ruby style');
		$this->assertEquals($d->age, 28, 'read age attribute');
		$this->assertEquals($d->getUniversalResponse(), 42, 'getAge()');
		$this->assertEquals($d->getUniversalResponse, 42, 'getUniversalResponse ruby style');
		$this->assertEquals($d->universalResponse, 48, 'read universalResponse attribute');
	}
	
	public function testRubyMethodStyle () {
		$d = new ABC;
		
		ob_start();
		$d->moo;
		$d->waf;
		$d->kwakwa;
		
		$this->assertEquals('moo !waf !kwa ! kwa !', ob_end_clean());
	}
}

?>